package com.five.bi.controller;

import com.five.bi.model.request.ListTableDesRequest;
import com.five.bi.model.request.QueryDataRequest;
import com.five.bi.service.DataTableService;
import com.five.bi.service.QueryDataService;
import com.five.bi.utils.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/v1")
public class QueryDataInfoController {

    @Autowired
    private QueryDataService queryDataService;

    @Autowired
    private DataTableService dataTableService;
    @PostMapping("/query")
    private JsonData queryDataInfo(@RequestBody QueryDataRequest queryDataRequest){
        List<Map<String, String>> maps = queryDataService.queryDataInfo(queryDataRequest);
        return JsonData.buildSuccess(maps);
    }

    @PostMapping("/schema/like")
    private JsonData tableLike(@RequestBody ListTableDesRequest listTableDesRequest){
        List<Map<String, String>> data = dataTableService.listLike(listTableDesRequest);
        if (null == data  || data.size()==0)
            return JsonData.buildError("error");
        return JsonData.buildSuccess(data);
    }

}
